#ifndef BRAYCASTVEHICLE_H
#define BRAYCASTVEHICLE_H

#include "body/bodypart_rigid.h"
#include "BulletCollision/NarrowPhaseCollision/btRaycastCallback.h"
// #include "body/bodypart_rigid_box.h"

struct btWheelContactPoint
{
	btRigidBody* m_body0;
	btRigidBody* m_body1;
	btVector3	m_frictionPositionWorld;
	btVector3	m_frictionDirectionWorld;
	btScalar	m_jacDiagABInv;
	btScalar	m_maxImpulse;


	btWheelContactPoint(btRigidBody* body0,btRigidBody* body1,const btVector3& frictionPosWorld,const btVector3& frictionDirectionWorld, btScalar maxImpulse)
		:m_body0(body0),
		m_body1(body1),
		m_frictionPositionWorld(frictionPosWorld),
		m_frictionDirectionWorld(frictionDirectionWorld),
		m_maxImpulse(maxImpulse)
	{
		btScalar denom0 = body0->computeImpulseDenominator(frictionPosWorld,frictionDirectionWorld);
		btScalar denom1 = body1->computeImpulseDenominator(frictionPosWorld,frictionDirectionWorld);
		btScalar	relaxation = 1.f;
		m_jacDiagABInv = relaxation/(denom0+denom1);
	}

};

struct interpolateNormalInfo
{
	unsigned int currpolycount;
	unsigned int prevpolycount;
	btVector3 currnormal;
	btVector3 prevnormal;
};

class bRaycastVehicle : public btRaycastVehicle
{
	public:
		bRaycastVehicle( const btVehicleTuning& tuning,btRigidBody* chassis, btVehicleRaycaster* raycaster );
// 		~bRaycastVehicle();

		btScalar getSpeed() { return m_currentVehicleSpeedKmHour; }
		void setSpeed(btScalar currentVehicleSpeedKmHour) { m_currentVehicleSpeedKmHour=currentVehicleSpeedKmHour; } 

		btScalar calcRollingFriction(btWheelContactPoint& contactPoint);
		
		btScalar customrayCast(btWheelInfo& wheel, unsigned int cwheel);
		void updateVehicle(btScalar step);

		btAlignedObjectArray <interpolateNormalInfo> interpolateInfo;

		btScalar forwardWheelSumSide;
		btScalar touchingfrontwheels;
		
};

// class  bTriangleRaycastCallback : public btTriangleRaycastCallback
// {
// 	public:
// 		bTriangleRaycastCallback( const btVector3& from,const btVector3& to, unsigned int flags=0 );
// };

#endif
